/**
 * 
 */
package com.xbang.attendance.web.action.system.treport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.demo2do.lighturl.annotation.Action;
import com.xbang.attendance.entity.order.PurchaseOrder;
import com.xbang.attendance.entity.system.Region;
import com.xbang.attendance.entity.treport.Treport;
import com.xbang.attendance.service.PurchaseOrderService;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class Search extends SearchActionSupport {

	private static final Log logger = LogFactory.getLog(Search.class);

	private static final long serialVersionUID = -1120551442020217513L;

	@Autowired
	private PurchaseOrderService purchaseOrderService;

	private List<Treport> treport;

	private List<Region> regions = new ArrayList<Region>();

//	private List<PurchaseDetails> purchaseDetails = new ArrayList<PurchaseDetails>();

	private Integer id;

	private PurchaseOrder purchaseOrder;
//
//	public String execute() throws Exception {
//
////		regions = purchaseOrderService.getObjects(Region.class);
//
//		return "search";
//	}

	/**
	 * @return
	 * @throws Exception
	 */
	@Action("/system/treport/search/do")
	public String doSearch() throws Exception {
		Map map  = new HashMap();
		logger.info("call search method by product ");
		String hqlSentence = "FROM Treport treport WHERE 1 = 1 ";
		if(!searchComponent.getParameters().isEmpty()){
			if(searchComponent.getParameters().get("eqTreportYear")!=null){
			int i = Integer.valueOf(searchComponent.getParameters().get("eqTreportYear").toString());
			map.put("eqTreportYear", i);
			}if(searchComponent.getParameters().get("eqTreportMonth")!=null){
			int j = Integer.valueOf(searchComponent.getParameters().get("eqTreportMonth").toString());
			map.put("eqTreportMonth", j);
			}
			searchComponent.setParameters(map);
		
		}
		if (searchComponent.getOrderParameters().isEmpty()) {
			searchComponent.addSearchElement("orderBy.treport.department", "DESC");
		}
		Result result = purchaseOrderService.searchByPage(hqlSentence, searchComponent, page);
		treport = result.getItems();
		page = result.getPage();

		return "index";
	}

//	@Action("/purchase/purchasedetails/${id}/search")
//	public String detailSearch() throws Exception {
//		regions = purchaseOrderService.getObjects(Region.class);
//
//		return "detail-search";
//	}
//
//	@Action("/purchase/purchasedetails/${id}/search/do")
//	public String doDetailSearch() throws Exception {
//		if (id != null) {
//			purchaseOrder = purchaseOrderService.getPurchaseOrderByKey(id);
//			String hqlSentence = " FROM PurchaseDetails purchasedetails WHERE 1 = 1 ";
//			searchComponent.addSearchElement("eq.purchasedetails.purchaseOrder.id", id);
//			Result result = purchaseOrderService.searchByPage(hqlSentence, searchComponent, page);
//
//			purchaseDetails = result.getItems();
//			page = result.getPage();
//		}
//		return "detail";
//	}
//
//	@Action("/purchase/purchasedetails/${id}")
//	public String details() throws Exception {
//
//		if (id != null) {
//			purchaseOrder = purchaseOrderService.getPurchaseOrderByKey(id);
//			String hqlSentence = "FROM PurchaseDetails purchasedetails WHERE 1 = 1";
//			searchComponent.addSearchElement("eq.purchasedetails.purchaseOrder.id", id);
//			Result result = purchaseOrderService.searchByPage(hqlSentence, searchComponent, page);
//			purchaseDetails = result.getItems();
//			page = result.getPage();
//		}
//
//		return "detail";
//	}

	

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}

	
	public List<Treport> getTreport() {
		return treport;
	}

	public void setTreport(List<Treport> treport) {
		this.treport = treport;
	}

	/**
	 * @return the regions
	 */
	public List<Region> getRegions() {
		return regions;
	}

	/**
	 * @param regions
	 *            the regions to set
	 */
	public void setRegions(List<Region> regions) {
		this.regions = regions;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	
	/**
	 * @return the purchaseOrder
	 */
	public PurchaseOrder getPurchaseOrder() {
		return purchaseOrder;
	}

	/**
	 * @param purchaseOrder
	 *            the purchaseOrder to set
	 */
	public void setPurchaseOrder(PurchaseOrder purchaseOrder) {
		this.purchaseOrder = purchaseOrder;
	}

}
